package cn.com.css.taxInspection.attention.controller;

import cn.com.css.taxInspection.attention.entity.JaajxxJadqhbEntity;
import cn.com.css.taxInspection.attention.entity.JaajxxJaxcyyEntity;
import cn.com.css.taxInspection.attention.service.JaajxxJadqhbService;
import cn.com.css.taxInspection.common.result.DataResult;
import cn.com.css.taxInspection.system.service.impl.HttpSessionService;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * ${comments}
 *
 * @author shaochangyang
 * @email l2l84o7o5@live.com
 * @date 2024-05-17 09:51:14
 */
@Controller
@RequestMapping("/")
public class JaajxxJadqhbController {
    @Autowired
    private JaajxxJadqhbService jaajxxJadqhbService;

    @Resource
    private HttpSessionService httpSessionService;

    /**
     * 跳转到页面
     */
    @GetMapping("/index/jaajxxJadqhb")
    public String jaajxxJadqhb() {
        return "jaajxxjadqhb/list";
    }

    @ApiOperation(value = "新增")
    @PostMapping("jaajxxJadqhb/add")
    @ResponseBody
    public DataResult add(@RequestBody JaajxxJadqhbEntity jaajxxJadqhb) {
        jaajxxJadqhbService.save(jaajxxJadqhb);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("jaajxxJadqhb/delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids) {
        jaajxxJadqhbService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("jaajxxJadqhb/update")
    @ResponseBody
    public DataResult update(@RequestBody JaajxxJadqhbEntity jaajxxJadqhb) {
        jaajxxJadqhbService.updateById(jaajxxJadqhb);
        return DataResult.success();
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("jaajxxJadqhb/listByPage")
    @ResponseBody
    @DS("oracle")
    public DataResult findListByPage(@RequestBody JaajxxJadqhbEntity req) {
        Page<JaajxxJadqhbEntity> page = new Page<>(req.getPage(), req.getLimit());
        LambdaQueryWrapper<JaajxxJadqhbEntity> queryWrapper = Wrappers.lambdaQuery();
        if (!StringUtils.isEmpty(req.getYxbz())) {
            queryWrapper.eq(JaajxxJadqhbEntity::getYxbz, req.getYxbz());
        }
        if (!StringUtils.isEmpty(req.getNsrsbh())) {
            queryWrapper.eq(JaajxxJadqhbEntity::getNsrsbh, req.getNsrsbh());
        }
        if (!StringUtils.isEmpty(req.getNsrmc())) {
            queryWrapper.eq(JaajxxJadqhbEntity::getNsrmc, req.getNsrmc());
        }
        if (!StringUtils.isEmpty(req.getAjbh())) {
            queryWrapper.eq(JaajxxJadqhbEntity::getAjbh, req.getAjbh());
        }
        IPage<JaajxxJadqhbEntity> iPage = jaajxxJadqhbService.page(page, queryWrapper);
        return DataResult.success(iPage);
    }

    @ApiOperation(value = "修改状态为完成")
    @PutMapping("jaajxxJadqhb/plupdatestatus")
    @ResponseBody
    public DataResult plupdatestatus(@RequestBody List<JaajxxJadqhbEntity> jaajxxJaxcyyEntities) {
        List<String> ids = new ArrayList<>();
        for (JaajxxJadqhbEntity obj : jaajxxJaxcyyEntities) {
            ids.add(obj.getId());
        }
        UpdateWrapper<JaajxxJadqhbEntity> updateWrapper = new UpdateWrapper<>();
        updateWrapper.in("id", ids);
        updateWrapper.set("STATUS", "1");
        updateWrapper.set("UPDATE_TIME", new Date());
        updateWrapper.set("XGR_DM", httpSessionService.getCurrentUserId());
        jaajxxJadqhbService.update(updateWrapper);
        return DataResult.success();
    }

    @ApiOperation(value = "失效")
    @PutMapping("jaajxxJadqhb/plupdateyxbz")
    @ResponseBody
    public DataResult plupdateyxbz(@RequestBody List<JaajxxJadqhbEntity> jaajxxJaxcyyEntities) {
        List<String> ids = new ArrayList<>();
        for (JaajxxJadqhbEntity obj : jaajxxJaxcyyEntities) {
            ids.add(obj.getId());
        }
        UpdateWrapper<JaajxxJadqhbEntity> updateWrapper = new UpdateWrapper<>();
        updateWrapper.in("id", ids);
        updateWrapper.set("YXBZ", "N");
        updateWrapper.set("UPDATE_TIME", new Date());
        updateWrapper.set("XGR_DM", httpSessionService.getCurrentUserId());
        jaajxxJadqhbService.update(updateWrapper);
        return DataResult.success();
    }

    @ApiOperation(value = "回退")
    @PutMapping("jaajxxJadqhb/plupdateback")
    @ResponseBody
    public DataResult plupdateback(@RequestBody List<JaajxxJadqhbEntity> jaajxxJaxcyyEntities) {
        List<String> ids = new ArrayList<>();
        for (JaajxxJadqhbEntity obj : jaajxxJaxcyyEntities) {
            ids.add(obj.getId());
        }
        UpdateWrapper<JaajxxJadqhbEntity> updateWrapper = new UpdateWrapper<>();
        updateWrapper.in("id", ids);
        updateWrapper.set("STATUS", "0");
        updateWrapper.set("UPDATE_TIME", new Date());
        updateWrapper.set("XGR_DM", httpSessionService.getCurrentUserId());
        jaajxxJadqhbService.update(updateWrapper);
        return DataResult.success();
    }
}
